﻿using System;
using viNews.Classes;
using viNews.Controllers;

public partial class Admin_Pages_viNews_Categories_ManageCategories : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownListParentCategories.DataSource = CategoryController.GetParentCategories();
            DropDownListParentCategories.DataTextField = "Name";
            DropDownListParentCategories.DataValueField = "CategoryID";
            DropDownListParentCategories.DataBind();
        }
    }

    protected void ButtonNewCategory_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(TextBoxNewCategory.Text))
            return;
        CategoryController.AddCategory(new Category(TextBoxNewCategory.Text, 0));
        Response.Redirect(Request.RawUrl);
    }
    protected void ButtonNewChildCategory_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(TextBoxNewChildCategory.Text))
            return;
        CategoryController.AddCategory(new Category(TextBoxNewChildCategory.Text, Convert.ToInt32(DropDownListParentCategories.SelectedValue)));
        Response.Redirect(Request.RawUrl);
    }
    protected void ButtonDeleteCategory_Click(object sender, EventArgs e)
    {
        CategoryController.DeleteCategory(Convert.ToInt32(DropDownCategories.CategoryId));
        Response.Redirect(Request.RawUrl);
    }
}

